package com.example.demo.his.leetcode;

/**
 * 用双向指针
 *
 * @auther zzc
 * @date 2021 03 24
 */
public class 反转字符串 {
    public static void main(String[] args) {
        char[] array = new char[]{'a', 'd', 's', 's', 'o'};
        System.out.println(getResult(array));
    }

    private static char[] getResult(char[] array) {
        if (array == null || array.length <= 1) {
            return null;
        }
        int start = 0;
        int end = array.length - 1;
        while (start < end) {
            swap(array, start, end);
            ++start;
            --end;
        }
        return array;

    }

    private static char[] swap(char[] array, int start, int end) {
        char tmp;
        tmp = array[start];
        array[start] = array[end];
        array[end] = tmp;
        return array;
    }
}
